import java.util.*;

class palindrome {
  // recursive function to get the smallest palindrome of the given string
  public static String minPalin (String str) {
    if (str.length() == 0) {
      return "";
    } else if (str.length() == 1) {
      return str;
    }
    int firstInt = Integer.valueOf(str.substring(0,1));
    int lastInt = Integer.valueOf(str.substring(str.length() - 1));
    
    if (firstInt <= lastInt) {
      String num = String.valueOf(firstInt);
      return num + minPalin(str.substring(1,str.length() - 1)) + num;
    } else {
      // make the last digit as 9 and decrease the previous digit by one
      String update = "9";
      int str_len = str.length();
      for (int i = str_len - 2; i >= 0; i--) {
        int cur_digit = Integer.valueOf(str.substring(i, i+1));
        if (cur_digit > 0) {
          update = str.substring(0, i) + String.valueOf(cur_digit - 1) + update;
          break;
        } else {
          update = "9" + update;
        }
      }
      // System.out.println("Current update is " + update + "; first element is " + update.substring(0,1) + "; rest of substring is " + update.substring(1));
      if (update.substring(0,1).equals("0")) {
        update = update.substring(1);
      }
      return minPalin(update);
    }
  }

  public static void run(Scanner scanner) {
    // Code here!
    String cur_int = scanner.nextLine();
    // Special case for single length string
    if (cur_int.length() == 0) {
      System.out.println("");
    } else if (cur_int.length() == 1) {
      System.out.println(String.valueOf(Integer.valueOf(cur_int) - 1));
    } else {
      System.out.println(minPalin(cur_int));
    }
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int cases = Integer.parseInt(scanner.nextLine());
    for(int i = 0; i < cases; i++) {
      run(scanner);
    }
  }
}